import 'package:aitao_flutter/common_ui/back_nav.dart';
import 'package:aitao_flutter/const/common_const.dart';
import 'package:aitao_flutter/style/color_style.dart';
import 'package:aitao_flutter/utils/sp_utils.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class LanguageSetPage extends StatefulWidget {
  const LanguageSetPage({super.key});

  @override
  State<LanguageSetPage> createState() => _LanguageSetPageState();
}

class _LanguageSetPageState extends State<LanguageSetPage> {
  List<Map> languageList = [
    {'title': 'SimplifiedChinese'.tr, 'value': 'zh_CN'},
    {'title': 'TraditionalChinese'.tr, 'value': 'zh_Hant'},
    {'title': 'English'.tr, 'value': 'en_US'}
  ];
  String languageValue = 'zh_CN';
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: BackNavigation(
          title: MineStringConst.languageText,
          rightTitle: '保存',
          rightTitleColor: ColorStyle.mainColor,
          rightBtnCallBack: () {
            debugPrint(languageValue);
            SpUtil.saveLanguage(languageValue);
          },
        ),
        body: Container(
          color: ColorStyle.whiteColor,
          padding: const EdgeInsets.all(15),
          child: ListView.builder(
            itemExtent: 60,
            itemBuilder: (context, index) {
              return GestureDetector(
                child: ListTile(
                  title: Text(
                    languageList[index]['title'],
                    style: const TextStyle(
                        fontSize: 18, color: ColorStyle.normalTextColor),
                  ),
                  trailing: Icon(
                    Icons.check,
                    color: languageValue == languageList[index]['value']
                        ? ColorStyle.mainColor
                        : ColorStyle.whiteColor,
                  ),
                ),
                onTap: () {
                  setState(() {
                    languageValue = languageList[index]['value'];
                  });
                },
              );
            },
            itemCount: languageList.length,
          ),
        ));
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    setState(() {
      languageValue = SpUtil.getLanguageStr();
    });
  }
}
